import java.util.Stack;

import org.junit.Test;

import jdk.tools.jlink.resources.plugins;

public class MyTest{
    private class BST{
        int element;
        BST leftChild;
        BST rightChild;
        public BST(int element){
            this.element=element;
        }
        public BST(int... elements){
            this.element=elements[0];
            for(int i=1;i<elements.length;i++){
                this.add(elements[i]);
            }
        }
        public void LDR(){
            Stack<BST> stack=new Stack<BST>();
            BST curr=this;
            while(!stack.isEmpty()||curr!=null){
                while(curr!=null){
                    stack.push(curr);
                    curr=curr.leftChild;
                }
                curr=stack.pop();
                System.out.print(curr.element+" ");
                curr=curr.rightChild;
            }
        }
        public void add(int element){
            BST curr=this;
            while(true){
                if(curr.element>element){
                    if(curr.leftChild==null){
                        curr.leftChild=new BST(element);
                        break;
                    }else{
                        curr=curr.leftChild;
                    }
                    
                }else{
                    if(curr.rightChild==null){
                        curr.rightChild=new BST(element);
                        break;
                    }else{
                        curr=curr.rightChild;
                    }
                }
            }
        }
    
        

    }
    @Test
    public void test1(){
        new BST(13,5,6,1,2,3,4).LDR();
        
    }
}